const mongoose = require('mongoose')
const { timeFormat } = require('../utils/format')

const WechatHomeSchema = new mongoose.Schema(
  {
    masterImage: {
      type: Array,
    },
    iconsList: {
      type: Array,
    },
    adverList: {
      type: Array,
    },
  },
  {
    timestamps: true,
  }
)
// 自定义日期格式化函数
function formatDate(date) {
  if (!date) return null
  return timeFormat(date)
}

WechatHomeSchema.pre('save', function (next) {
  formatDate(this.createdAt)
  formatDate(this.updatedAt)
  next()
})

const WechatHome = mongoose.model('WechatHome', WechatHomeSchema)

module.exports = {
  WechatHome,
}
